<template>
  <!-- <Teleport> 是一个内置组件，使我们可以将一个组件的一部分模板“传送”到该组件的 DOM 层次结构之外的 DOM 节点中。 -->
  <div class="">
    <button @click="open = true">Open Modal</button>
  </div>
  <Teleport to="body">
    <div v-if="open" class="modal-mask" @click="open = false">
      <div class="modal-content">
        <p>Hello from the modal!</p>
        <button @click.stop="open = false">Close</button>
      </div>
    </div>
  </Teleport>
</template>

<script setup lang="ts">
import { ref } from 'vue'
const open = ref(false)
</script>

<style lang="less" scoped>
.modal {
  &-mask {
    position: fixed;
    z-index: 9998;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: table;
    transition: opacity 0.3s ease;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }

  &-content {
    background-color: #fff;
    padding: 16px;
    border-radius: 16px;
  }
}
</style>
